package class4;

/**
 * https://leetcode.cn/problems/missing-number/
 * 丢失的数字
 */
public class Code14_missingNumber {
    public static void main(String[] args) {
        int[] nums = {3, 0, 1};
        int i = missingNumber(nums);
        System.out.println("i = " + i);
    }

    public static int missingNumber(int[] nums) {
        int eorAll = nums.length, eorHas = 0;
        for (int i = 0; i < nums.length; i++) {
            eorAll ^= i;
            eorHas ^= nums[i];
        }
        return eorAll ^ eorHas;
    }
}
